<template>
<div>
  <h2>Vue3快速入门</h2>
</div>
  <div class="listBox">
    <div class="listItem" v-for="item in allRouters" :key="item.path" @click="goPath(item)">
      <span>{{ item.meta.title }}</span>
    </div>
  </div>
</template>

<script>
import { defineComponent } from "vue";
import { useRouter } from "vue-router";

export default defineComponent({
  setup() {
    const router = useRouter();
    // 获取全路由
    const allRouters = router
      .getRoutes()
      .map((item) => {
        return {
          path: item.path,
          meta: item.meta,
        };
      })
      .slice(0, -1);

    // 跳转路由
    function goPath(cur) {
      router.push(cur.path);
    }

    return { allRouters, goPath };
  },
});
</script>

<style scoped>
.listBox {
  margin-left: 50%;
  transform: translateX(-50%);
  width: 80vw;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
}

.listItem {
  box-sizing: border-box;
  width: 19%;
  margin-bottom: 10px;
  height: 80px;
  outline: 1px solid #ddd;
  text-align: center;
  line-height: 80px;
  padding: 0 5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.listItem::after {
  -webkit-transition: all 0.5s;
  -moz-transition: all 0.5s;
  -o-transition: all 0.5s;
  transition: all 0.5s;
}

.listItem {
  border: 1px solid #c147e6;
  color: #c147e6;
  position: relative;
  z-index: 1;
  /* 将字母全转换为大写 */
  /* text-transform: uppercase; */
}

.listItem:hover {
  color: #fff;
  cursor: pointer;
}

.listItem::before,
.listItem::after {
  background: #c147e6;
  content: "";
  position: absolute;
  z-index: -2;
  border-radius: 3px;
}

.listItem {
  overflow: hidden;
}

.listItem::after {
  height: 100%;
  left: -50%;
  top: 0;
  transform: skew(50deg);
  transition-duration: 0.6s;
  transform-origin: top left;
  width: 0;
}

.listItem:hover:after {
  height: 100%;
  width: 150%;
}
</style>
